package com.lwx.mongo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

import org.bson.types.ObjectId;
import org.junit.Before;
import org.junit.Test;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

public class MongoMain {
    MongoManager mongoManager = new MongoManager();
    String tableName = "table1";
    
    @Before
    public void setUp(){
    }
    
    @Test
    public void insert(){
        Long start = System.currentTimeMillis();
        List<DBObject> list = new ArrayList<DBObject>();
        for(int i = 10000000; i < 20000000; i++){
            BasicDBObject doc = new BasicDBObject();
            doc.put("id", i);
            doc.put("name", UUID.randomUUID());
            doc.put("class", i);
            doc.put("age", new Random().nextInt(100));
            list.add(doc);
        }
        mongoManager.insert(tableName, list);
        System.out.println(System.currentTimeMillis() - start);
    }
    
    @Test
    public void delete(){
        BasicDBObject doc = new BasicDBObject();
        doc.put("id", 1);
        mongoManager.delete(tableName, doc);
    }
    
    @Test
    public void find(){
        Long start = System.currentTimeMillis();
        BasicDBObject doc = new BasicDBObject();
        doc.put("_id", new ObjectId("5540a0c75b3d1d362313f027"));
        mongoManager.find(tableName, doc);
        //System.out.println(mongoManager.find(tableName, doc));
        System.out.println(System.currentTimeMillis() - start);
        
    }
    
    
}
